package com.woorigil.social.domain.category;

import org.springframework.stereotype.Component;

import com.woorigil.social.Context;
import com.woorigil.social.domain.deal.Deal;

@Component (value="CPMapper")
public class CoupangCategoryMapper implements CategoryMapper {
	@Override
	public int getCategoryId(Deal deal) {
		int categoryId = 0;
		if ("지역".equals(deal.getCategory())) {
			categoryId = Context.getCategoryId(getLocalName(deal.getSection1().replace(" 전체", "")));
		} else if ("쇼핑".equals(deal.getCategory())) {
			categoryId = Context.getCategoryId(getLocalName(deal.getSection1()));
		} else if ("여행/레저".equals(deal.getCategory())) {
			categoryId = Context.getCategoryId(getLocalName(deal.getSection1()));
		} else if ("문화".equals(deal.getCategory())) {
			categoryId = Context.getCategoryId(getLocalName(deal.getSection2()));
		}
		return (categoryId == 0)? 100 : categoryId;
	}
	
	protected String getLocalName(String category) {
		if ("전남".contains(category) || "전북".contains(category)) {
			return "전라";
		} else if ("경남".contains(category) || "경북".contains(category)) {
			return "경상";
		} else if ("충남".contains(category) || "충북".contains(category)) {
			return "충청";
		}
		return category;
	}
}
